package com.tyk.bookstore.front.payment.util;

import com.tyk.bookstore.front.common.core.model.enume.PaymentWay;
import com.tyk.bookstore.front.common.core.util.ComUtil;
import com.tyk.bookstore.front.payment.strategy.enume.PayType;

/**
 * @author tyk
 * @description PaymentUtil
 */
public class PaymentUtil {


    private static final int PAYMENT_NO_LENGTH = 16;

    /**
     * 通用支付类型转系统支付类型
     *
     * @param type 通用支付类型
     * @return 系统支付类型
     */
    public static PaymentWay toPaymentWay(PayType type) {
        if (type == null) return null;
        return switch (type) {
            case LOCAL -> PaymentWay.LOCAL;
            case ALIPAY -> PaymentWay.ALIPAY;
            case WE_CHAT -> PaymentWay.WE_CHAT;
            default -> null;
        };
    }

    /**
     * 系统支付类型转通用支付类型
     *
     * @param paymentWay 系统支付类型
     * @return 通用支付类型
     */
    public static PayType toPayType(PaymentWay paymentWay) {
        if (paymentWay == null) return null;
        return switch (paymentWay) {
            case LOCAL -> PayType.LOCAL;
            case ALIPAY -> PayType.ALIPAY;
            case WE_CHAT -> PayType.WE_CHAT;
            default -> null;
        };
    }

    /**
     * 支付单号
     *
     * @return
     */
    public static String paymentNo() {
        return ComUtil.randomIntSeqNotStartZero(PAYMENT_NO_LENGTH);
    }
}
